package com.woniuxy.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.Manager;
import com.woniuxy.entity.Usermannge;

import com.woniuxy.entity.UsermanngeDto;
import com.woniuxy.service.UsermanngeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * (Usermannge)表控制层
 *
 * @author makejava
 * @since 2021-05-15 14:52:41
 */
@RestController
@RequestMapping("usermannge")
public class UsermanngeController {
    /**
     * 服务对象
     */
    @Resource
    private UsermanngeService usermanngeService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Usermannge selectOne(Integer id) {
        return this.usermanngeService.queryById(id);
    }


    /**
     * Description : 根据穿的页码和每页的数据，给出对应页面的数据  <br/>
     * ChangeLog : 1. 创建 ( 19:39 );
     * @param startpage
     * @param pagesize
     * @return com.github.pagehelper.PageInfo<com.woniuxy.entity.Usermannge>
    */
    @GetMapping("selectAll")
    public PageInfo<Usermannge> selectAll(int startpage, int pagesize){
        PageHelper.startPage(startpage,pagesize);
        Page<Usermannge> page = (Page<Usermannge>) this.usermanngeService.queryAll();
        PageInfo<Usermannge> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }


    /**
     * Description : 模糊查询  <br/>
     * ChangeLog : 1. 创建 ( 19:59 );
     * @param usermanngeDto
     * @return com.github.pagehelper.PageInfo<com.woniuxy.entity.Usermannge>
    */

    @PostMapping("search")
    public PageInfo<Usermannge> search(@RequestBody UsermanngeDto usermanngeDto){
        PageHelper.startPage(usermanngeDto.getPage(),usermanngeDto.getLimit());
        Page<Usermannge> page =(Page<Usermannge>) this.usermanngeService.search(usermanngeDto.getUsermannge());
        PageInfo<Usermannge>pageInfo = new PageInfo<>(page);
        return pageInfo;
    }


    /**
     * Description : 增加用户表  <br/>
     * ChangeLog : 1. 创建 ( 20:50 );
     * @param usermannge
     * @return java.lang.String
    */

    @PostMapping("insert")
    public String insert(@RequestBody Usermannge usermannge){
        int i = this.usermanngeService.insert(usermannge);
        if (i>0){
            return "success";
        }
        return "failure";
    }


    /**
     * Description : 修改用户表  <br/>
     * ChangeLog : 1. 创建 ( 20:50 );
     * @param usermannge
     * @return String
    */
    @PostMapping("update")
    public String update(@RequestBody Usermannge usermannge){
        int i = this.usermanngeService.update(usermannge);
        if (i > 0){
            return "success";
        }
        return "failure";

    }


    /**
     * Description : 删除  <br/>
     * ChangeLog : 1. 创建 ( 20:56 );
     * @param customerId
     * @return java.lang.String
    */

    @PostMapping("delete/{customerId}")
    public String delete(@PathVariable("customerId") int customerId){
        boolean b = this.usermanngeService.deleteById(customerId);
        if (b){
            return "success";
        }
        return "failure";
    }

}
